package com.demo.controller;

import com.demo.common.Result;
import com.demo.entity.riot.MatchInfo;
import com.demo.exception.ApiException;
import com.demo.service.deepseek.DeepSeekService;
import com.demo.service.deepseek.PlayerAnalysisService;
import com.demo.service.riot.RiotMatchService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/ai")
public class AIChatController {
    @Resource
    private final DeepSeekService deepSeekService;

    @Resource
    private final RiotMatchService riotMatchService;

    @Resource
    private final PlayerAnalysisService playerAnalysisService;

    public AIChatController(DeepSeekService deepSeekService, RiotMatchService riotMatchService, PlayerAnalysisService playerAnalysisService) {
        this.deepSeekService = deepSeekService;
        this.riotMatchService = riotMatchService;
        this.playerAnalysisService = playerAnalysisService;
    }

    @GetMapping("/chat")
    public Result chat(@RequestBody String prompt){
        try {
            String answer = deepSeekService.chatCompletion(prompt);
            return Result.success(answer);
        } catch (ApiException e) {
            throw new RuntimeException("服务调用失败");
        }
    }

    @GetMapping("/analyze/{serverRegion}/{puuid}")
    public Result analyze(@PathVariable String serverRegion, @PathVariable String puuid) throws IOException, ApiException {
        return Result.success(playerAnalysisService.analyzePlayerMatches(serverRegion, puuid, 2));
    }
}
